package com.sp.system.user.core.utils;

import lombok.Data;

import java.io.Serializable;

@Data
public class ContentResult<T> extends BaseResult implements Serializable {

    private T result;

    /**
     * 返回成功，带提示信息
     *
     * @param data
     * @param message
     * @param <D>
     * @return
     */
    public static <D> ContentResult<D> successResult(D data, String message) {
        ContentResult<D> result = new ContentResult<D>();
        result.result = data;
        result.success = true;
        result.status = SUCCESS_CODE;
        result.setMessage(message);
        return result;
    }

    /**
     * 返回失败，带提示信息
     *
     * @param data
     * @param message
     * @param <D>
     * @return
     */
    public static <D> ContentResult<D> errorResult(D data, String message) {
        ContentResult<D> result = new ContentResult<D>();
        result.result = data;
        result.success = false;
        result.status = ERROR_CODE;
        result.setMessage(message);
        return result;
    }

    /**
     * 返回失败，带提示信息
     *
     * @param code, message
     * @param message
     * @param <D>
     * @return
     */
    public static <D> ContentResult<D> errorResult(int code, String message) {
        ContentResult<D> result = new ContentResult<D>();
        result.success = false;
        result.status = code;
        result.setMessage(message);
        return result;
    }

}
